# (setq py-indent-offset 2)
from java.lang import *
from java.util.concurrent import *
from it.unimi.dsi.webgraph import *
from ranker import RankerTask
import os

ITERS = 6
TASKS = 4
bdir = r'C:\packages\jylab-0.2\examples\webmatrix'
relbname = r'cnr-2000'
bname = os.path.join(bdir, relbname)
graph = BVGraph.loadOffline(String(bname))
barrier = CyclicBarrier(TASKS + 1)
pool = Executors.newCachedThreadPool()
tasks = []
futures = []
alpha = 0.75

for i in range(TASKS):
  task = RankerTask(graph, alpha, ITERS, barrier)
  tasks.append(task)
  future = pool.submit(task)
  futures.append(future)
  alpha = alpha + 0.05
barrier.await()

print 'Pagerank computation tasks completed'
print '[nodes = %d, links = %d]' % (graph.n,
                                    graph.m)
for i in range(TASKS):
  alpha = tasks[i].alpha
  log = tasks[i].logger.getvalue()
  lastlog = log.split('\n')[-2]
  print 'alpha = %.2f : %s' % (alpha, lastlog)  
        

    
        
        
